package com.yesido.javabase.leetcode.easy;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

/**
 * @author yesido
 * @description
 * @date 2023-07-04 1:48
 * @Version 8.3
 */
public class LD20 {
    public static final Map<Character,Character> MP = new HashMap<Character,Character>(){{
        put('(',')');
        put('{','}');
        put('[',']');
    }};
    /**
     * (){}[]
     * @param s
     * @return
     */
    private  boolean test1(String s) {
        char[] chars = s.toCharArray();
        // 栈 先进后出的数据结构
        LinkedList<Character> stack = new LinkedList<>();
        for (char ch : chars) {
            if (MP.containsKey(ch)){
                stack.push(MP.get(ch));
            }else {
                if (stack.isEmpty()||stack.pop()!=ch){
                    return false;
                }
            }

        }
        return stack.isEmpty();
    }

}
